<script type="text/javascript">

  albumRemember = function()
  {
    swfu.setPostParams({
      '<%= ActionController::Base.session_options[:key] %>' : '<%= cookies[ActionController::Base.session_options[:key]] %>',
      '<%= request_forgery_protection_token %>' : '<%= form_authenticity_token %>',
      'album_name' : $F('album_name'),'author_id' : '<%= current_valleyer_id %>'
    })
  }

  show_the_lastest_photo = function()
  {
    <%= remote_function :update => :js_run,
         :url => valleyers_show_albums_show_photo_url(:none),
         :with => "'&album_name=' + $F('album_name')",
         :method => :get
    %>
  }

  var swfu = new SWFUpload({
    // Backend Settings
    upload_url: "<%= valleyers_show_albums_show_photos_url %>",
    post_params: {
      '<%= ActionController::Base.session_options[:key] %>' : '<%= cookies[ActionController::Base.session_options[:key]] %>',
      '<%= request_forgery_protection_token %>' : '<%= form_authenticity_token %>',
      'album_name' : $F('album_name'),'author_id' : '<%= current_valleyer_id %>'
    },


    // File Upload Settings
    file_size_limit : "10 MB",	// 2MB
    file_types : "*.jpg",
    file_types_description : "JPG Images",
    file_upload_limit : "0",

    // Event Handler Settings - these functions as defined in Handlers.js
    //  The handlers are not part of SWFUpload but are part of my website and control how
    //  my website reacts to the SWFUpload events.
    file_queue_error_handler : fileQueueError,
    file_dialog_complete_handler : fileDialogComplete,
    upload_progress_handler : uploadProgress,
    upload_error_handler : uploadError,
    upload_success_handler : show_the_lastest_photo,
    upload_complete_handler : uploadComplete,

    // Button Settings
    button_placeholder_id : "spanButtonPlaceholder",
    button_width: 129,
    button_height: 43,
    button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
    button_cursor: SWFUpload.CURSOR.HAND,

    // Flash Settings
    flash_url : "/assets/swfupload.swf",

    custom_settings : {
      upload_target : "divFileProgressContainer"
    },
    // Debug Settings
    debug: false
  });
</script>
<div class="addPicture">
  <div class="title">
    <p>相册&nbsp;:&nbsp;</p>
    <%= text_field_with_auto_complete("album",
             :name,{:value => @album_name},{
               :url => auto_complete_albums_url,
               :with => "'&name=' + $F('album_name') ",
               :method =>:get,
               :skip_style => true
             }) %>
  </div>
  <div class="plug-in">
    <form>
      <div class="spanButton">
        <span id="spanButtonPlaceholder"></span>
      </div>
    </form>
    <%= link_to_remote image_tag("valleyer/photo_fix.jpg"),
          :update => "album_replace",
          :url => valleyers_show_album_url(current_valleyer),
          :method => :get,
          :html => {
          :class => "add_photo_button"
          }
        %>
    <%= link_to_remote image_tag("valleyer/add_photo_back.jpg"),
          :update => "album_replace",
          :url => valleyers_show_album_url(current_valleyer),
          :method => :get,
          :html => {
          :class => "add_photo_button"
          }
        %>
    <div id="divFileProgressContainer"></div>
    <div id="thumbnails"></div>
    <div id="be_photo"></div>
    <div id="js_run"></div>
  </div>
</div>
<%= observe_field :album_name,
      :function => 'albumRemember();',
      :frequency => 0.5 %>